package com.ldc.commonlibs.uts

import android.app.Activity
import android.app.Application
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.ldc.commonlibs.common.ViewModelBase

/**
 *
 *author DELL
 *dateTime 2021/12/10-11:37
 */
object ViewModelUtils {

    fun <T : ViewModelBase> create(
        application: Application,
        clazz: Class<out T>,
    ): T =
        ViewModelProvider.AndroidViewModelFactory
            .getInstance(application)
            .create(clazz)


    fun <T : ViewModelBase> create(activity: Activity, clazz: Class<out T>): T =
        create(activity.application, clazz)

    fun <T : ViewModelBase> create(fragment: Fragment, clazz: Class<out T>): T =
        create(fragment.requireActivity(), clazz)
}
